package com.family.gmall.list.controlloer;

import com.family.gmall.common.result.Result;
import com.family.gmall.list.service.SearchService;
import com.family.gmall.model.list.SearchParam;
import com.family.gmall.model.list.SearchResponseVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Auther: family
 * @Date: 2023/7/24 17:49
 * @Description:
 */
@RestController
@RequestMapping("/api/list")
public class ListApiController {

    @Resource
    private SearchService searchService;
    @Resource
    private ElasticsearchRestTemplate restTemplate;

    @ApiOperation("上架商品")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("inner/upperGoods/{skuId}")
    public Result upperGoods(@PathVariable("skuId") Long skuId) {
        searchService.upperGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("下架商品")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("inner/lowerGoods/{skuId}")
    public Result lowerGoods(@PathVariable("skuId") Long skuId) {
        searchService.lowerGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("更新商品incrHotScore")
    @ApiImplicitParam(name = "skuId", value = "skuId", required = true)
    @GetMapping("/inner/incrHotScore/{skuId}")
    public Result incrHotScore(@PathVariable("skuId") Long skuId) {
        // 调用服务层
        searchService.incrHotScore(skuId);
        return Result.ok();
    }

    @ApiOperation("搜索商品")
    @ApiImplicitParam(name = "searchParam", value = "searchParam", required = true)
    @PostMapping
    public Result list(@RequestBody SearchParam searchParam) throws IOException {
        SearchResponseVo response = searchService.search(searchParam);
        return Result.ok(response);
    }
}
